public class Text6 {
    public static void main(String[] args) {
      han(1,'A','B','C');
        System.out.println();
      han(2,'A','B','C');
        System.out.println();
      han(3,'A','B','C');
    }


   public static void han(int n,char p1,char p2,char p3){
        if(n == 1){
            move(p1,p3);
            return;
        }
       han(n-1,p1,p3,p2);
        move(p1,p3);
       han(n-1,p2,p1,p3);
   }
     public static void move(char p1,char p2){
         System.out.print(p1+"->"+p2+" ");
     }

}
